extends ../layout/admin

block head
    script(src="/bower_components/ace-builds/src-min/ace.js")
    script(src="/bower_components/ace-builds/src-min/theme-github.js")
    script(src="/bower_components/ace-builds/src-min/mode-markdown.js")

block content
    h1 New Post
    hr

    form.post-form(method="post",action="/admin/posts")
        .item-row
            input(type="hidden", name='_csrf', value='#{_csrf.token}')
        .form-group
            label 标题
            input.form-control(type="text", name="title", value='#{postForm.getTitle()}')

        .form-group
            label 正文
            textarea.form-control#content(name="content", style="display:none;")
                = postForm.getContent()
            div#content-editor
                #{postForm.getContent()}

        .form-group
            label 摘要
            textarea.form-control#summary(name="summary", style="display:none;")
                = postForm.getSummary()
            div#summary-editor
                #{postForm.getSummary()}
        .item-row
            hr
            .row
                .col-sm-2
                    .form-group
                        label Type
                        select.form-control(name="postType")
                            for item in postTypes
                                if item != postForm.getPostType()
                                    option(value="#{item.getId()}") #{item.getName()}
                                else
                                    option(value="#{item.getId()}", selected="selected") #{item.getName()}
                .col-sm-2
                    .form-group
                        label Format
                        select.form-control(name="postFormat")
                            for format in postFormats
                                if format != postForm.getPostFormat()
                                    option(value="#{format.getId()}") #{format.getDisplayName()}
                                else
                                    option(value="#{format.getId()}", selected="selected") #{format.getDisplayName()}
                .col-sm-2
                    .form-group
                        label Status
                        select.form-control(name="postStatus")
                            for status in postStatus
                                if status != postForm.getPostStatus()
                                    option(value="#{status.getId()}") #{status.getName()}
                                else
                                    option(value="#{status.getId()}", selected="selected") #{status.getName()}

                .col-sm-2
                    .form-group
                        label Permalink
                        input.form-control(name="permalink", value="#{postForm.getPermalink()}")

                .col-sm-3
                    .form-group
                        label Tags
                        input.form-control(name="postTags", value="#{postForm.getPostTags()}")
        .item-row
            hr
            button.btn.btn-primary.btn-block(type="submit") Create new post

    script
        var editor = ace.edit("content-editor");
        var summaryEditor = ace.edit("summary-editor");

        editor.setTheme("ace/theme/github");
        summaryEditor.setTheme("ace/theme/github");

        var MarkdownMode = ace.require("ace/mode/markdown").Mode;
        editor.getSession().setMode(new MarkdownMode());
        editor.getSession().setUseWrapMode(true);

        summaryEditor.getSession().setMode(new MarkdownMode());
        summaryEditor.getSession().setUseWrapMode(true);

        $("form").submit(function(){
            $("#content").val(editor.getValue());
            $("#summary").val(summaryEditor.getValue());
            return true;
        });

